package com.softer.wxzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.common.enums.NumStrEnum;
import com.softer.wxzj.common.enums.NumberEnum;
import com.softer.wxzj.common.enums.ShiroResultEnum;
import com.softer.wxzj.common.error.CourseException;
import com.softer.wxzj.common.logic.GenerateAccount;
import com.softer.wxzj.common.shiro.ShiroUtil;
import com.softer.wxzj.common.util.DateUtils;
import com.softer.wxzj.common.util.OperUtil;
import com.softer.wxzj.common.util.ShiroUserUtil;
import com.softer.wxzj.common.util.UUIDUtil;
import com.softer.wxzj.entity.*;
import com.softer.wxzj.mapper.*;
import com.softer.wxzj.service.OrgRegionService;
import com.softer.wxzj.service.SysOperatorService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
 * UserServiceImpl class
 *
 * @author zcz
 * @date 2019/1/16
 */
@Service
public class SysOperatorServiceImpl implements SysOperatorService {
    @Autowired
    private OperUtil operUtil;
    @Autowired
    private SysOperatorMapper sysOperatorMapper;
    @Autowired
    private OperUtil zoneCodeUtil;
    @Autowired
    private BaseOrganizationMapper baseOrganizationMapper;
    @Autowired
    private BaseOwnerCommitteeMapper baseOwnerCommitteeMapper;
    @Autowired
    private BaseRegionInfoMapper baseRegionInfoMapper;
    @Autowired
    private BaseBuildInfoMapper baseBuildInfoMapper;
    @Autowired
    private BaseCellInfoMapper baseCellInfoMapper;
    @Autowired
    private BaseHouseInfoMapper baseHouseInfoMapper;
    @Autowired
    private DepReqListInfoMapper depReqListInfoMapper;
    @Autowired
    private DepReqMapper depReqMapper;
    @Autowired
    private ExpProjectReqMapper expProjectReqMapper;
    @Autowired
    private ExpPayReqMapper expPayReqMapper;
    @Autowired
    private FlowInstanceMapper flowInstanceMapper;
    @Autowired
    private BaseOwnerInfoMapper baseOwnerInfoMapper;
    @Autowired
    private BaseModifyReqMapper baseModifyReqMapper;
    @Autowired
    private TransReqMapper transReqMapper;
    @Autowired
    private RefReqMapper refReqMapper;
    @Autowired
    private RefPayInfoMapper refPayInfoMapper;
    @Autowired
    private AccKeepAccountMapper accKeepAccountMapper;
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private GenerateAccount generateAccount;
    @Autowired
    private BaseOrganizationServiceImpl baseOrganizationService;
    @Autowired
    private OrgRegionMapper orgRegionMapper;
    @Autowired
    private OrgBuildAuditMapper orgBuildAuditMapper;
    @Autowired
    private ZoneCodeMapper zoneCodeMapper;
    @Autowired
    private OrgRegionService orgRegionService;
    private static final String FIVE = "05";
    private static final String SIX = "06";
    @Value("${pwd}")
    private String pwd;

    @Override
    public synchronized CommonResult insert(SysOperator sysOperator) {
        if (sysOperator == null) {
            return CommonResult.ResponseResult(NumberEnum.ZERO.getNum());
        }
        String operNo = "100000";
        //查询最大账号
        String maxOperNo = sysOperatorMapper.getMaxOperNo();
        if (StringUtils.isNotBlank(maxOperNo)) {
            operNo = String.valueOf(Integer.parseInt(maxOperNo) + 1);
        }
        String salt = ShiroUtil.createSalt();
        String pass = getPassWord(sysOperator.getOperPwd());
        String passWord = ShiroUtil.createPassWord(pass, salt);
        sysOperator.setSalt(salt);
        sysOperator.setOperPwd(passWord);
        sysOperator.setOperNo(operNo);
        if (StringUtils.isBlank(sysOperator.getState())) {
            sysOperator.setState("1");
        }
        int i = sysOperatorMapper.insert(sysOperator);
        return CommonResult.ResponseResult(i, "操作成功！用户名:" + operNo + ",密码:" + pass);
    }


    @Override
    public CommonResult update(SysOperator sysOperator) {
        SysOperator sysOper1 = setUpdateValue(sysOperator);
        int i = sysOperatorMapper.update(sysOper1);
        return CommonResult.ResponseResult(i);
    }

    private int codeType(String code, String id) {
        if (code.equals("01") || code.equals("02") || code.equals("03") || code.equals("04") || code.equals("08")) {
            BaseOrganization baseOrganization = baseOrganizationMapper.getInfo(id);
            if (null != baseOrganization) {
                if (!NumStrEnum.TWO.getNum().equals(baseOrganization.getState())) {
                    return 0;
                }
            }
        } else if (FIVE.equals(code) || SIX.equals(code)) {
            BaseOwnerCommittee baseOwnerCommittee = baseOwnerCommitteeMapper.getInfo(id);
            if (null != baseOwnerCommittee) {
                if (!NumStrEnum.TWO.getNum().equals(baseOwnerCommittee.getState())) {
                    return 0;
                }
            }
        }
        return 1;
    }


    @Override
    public CommonResult delete(String id) {
        int i = 0;
        //查询有没有添加企业
        SysOperator sysCorpOperator = sysOperatorMapper.getInfo(id);
        //删除
        if (StringUtils.isNotBlank(sysCorpOperator.getCompanyNo())) {
            int num = codeType(sysCorpOperator.getCompanyNo(), sysCorpOperator.getCompanyId());
            if (num == 0) {
                return new CommonResult(i, "该账号被使用过无法删除");
            }
        }

        i = baseOrganizationMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有添加业委会
        i = baseOwnerCommitteeMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有添加缴存
        i = depReqMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有添加缴存申请
        i = depReqListInfoMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有使用
        i = expProjectReqMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        i = expPayReqMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询又没审核
        i = flowInstanceMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有添加业主
        i = baseOwnerInfoMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有添加自然幢
        i = baseBuildInfoMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有添加单元
        i = baseCellInfoMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有添加小区
        i = baseRegionInfoMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //有没有变更
        i = baseModifyReqMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询有没有过户
        i = transReqMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //查询退款
        i = refReqMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        i = refPayInfoMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        //记账
        i = accKeepAccountMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        i = accKeepAccountMapper.selectVerifier(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        i = accKeepAccountMapper.selectSettlement(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        i = accKeepAccountMapper.selectCreaterName(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        i = baseHouseInfoMapper.selectCreater(sysCorpOperator.getOperNo());
        if (i > 0) {
            return new CommonResult(i, "该角色被使用过无法删除");
        }
        i = sysOperatorMapper.delete(id);
        return CommonResult.ResponseResult(i);
    }

    @Override
    public PageInfo<SysOperator> getList(Page page, SysOperator sysOperator) {
        //只有紧跟在PageHelper.startPage方法后的第一个Mybatis的查询（Select）方法会被分页。
        sysOperator.setZoneCode(zoneCodeUtil.getZoneCode());
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<SysOperator> list = sysOperatorMapper.getList(sysOperator);
        PageInfo<SysOperator> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 密码重置
     *
     * @param id
     * @return
     */
    @Override
    public CommonResult resetPassword(String id) {
        SysOperator operator = new SysOperator();
        String salt = ShiroUtil.createSalt();
        String passWord = ShiroUtil.createPassWord(getPassWord(operator.getOperPwd()), salt);
        operator.setSalt(salt);
        operator.setOperPwd(passWord);
        operator.setId(id);
        int i = sysOperatorMapper.update(operator);
        return CommonResult.ResponseResult(i, "密码已重置，新密码为：123456");
    }

    @Override
    public CommonResult resetCorpPassword(String id) {
        SysCorpOperator operator = new SysCorpOperator();
        String salt = ShiroUtil.createSalt();
        String passWord = ShiroUtil.createPassWord(getCorpPassWord(operator), salt);
        operator.setSalt(salt);
        operator.setOperPwd(passWord);
        operator.setId(id);
        int i = 0;//sysCorpOperatorMapper.update(operator);
        return CommonResult.ResponseResult(i, "密码已重置，新密码为：123456");
    }

    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @Override
    public SysOperator getInfo(String id) {
        return sysOperatorMapper.getInfo(id);
    }

    /**
     * 设置初始密码
     *
     * @param pwd
     * @return
     */
    public String getPassWord(String pwd) {
        if (StringUtils.isBlank(pwd)) {
            return "123456";
        }
        return pwd;
    }

    public String getCorpPassWord(SysCorpOperator sysOperator) {
        if (null != sysOperator && StringUtils.isBlank(sysOperator.getOperPwd())) {
            return "123456";
        }
        return sysOperator.getOperPwd();
    }


    /**
     * 对应修改信息赋值
     *
     * @param sysOperator
     * @return
     */
    public SysOperator setUpdateValue(SysOperator sysOperator) {
        if (null != sysOperator) {
            //不允许修改密码
            sysOperator.setOperPwd(null);
            //改状态
            if (StringUtils.isNotBlank(sysOperator.getState())) {
                if (NumberEnum.ONE.getNum() == Integer.parseInt(sysOperator.getState())) {
                    sysOperator.setOpenOperName(ShiroUserUtil.getUserName());
                } else if (NumberEnum.ZERO.getNum() == Integer.parseInt(sysOperator.getState())) {
                    sysOperator.setCloseOperName(ShiroUserUtil.getUserName());
                }
            }
        }
        return sysOperator;
    }

    /**
     * 根据登录账号查询 该登录人员的区域编码  （查询结果可能为空、null）
     *
     * @param opesNo 登录账号
     * @return
     */
    @Override
    public String getZoneCode(String opesNo) {
        return sysOperatorMapper.getZoneCode(opesNo);
    }

    /**
     * 开启或关闭用户
     *
     * @param id    用户Id
     * @param state 状态（1开启，0关闭）
     * @return 操作结果
     */
    @Override
    public CommonResult operate(String id, String state) {
        SysOperator sysOperator = new SysOperator();
        //获取登录人
//        String userName = "admin";
        String userName = ShiroUserUtil.getUserName();
        sysOperator.setId(id);
        sysOperator.setState(state);
        sysOperator.setModifier(userName);
        if (String.valueOf(NumberEnum.ZERO.getNum()).equals(state)) {
            sysOperator.setCloseOperName(userName);
        } else {
            sysOperator.setOpenOperName(userName);
        }
        int num = sysOperatorMapper.operate(sysOperator);
        return CommonResult.ResponseResult(num);
    }

    /**
     * 密码修改
     *
     * @param newPassword
     * @param oldPassword
     * @return
     */
    @Override
    public CommonResult updatePassword(String newPassword, String oldPassword) {
        SysOperator oper = sysOperatorMapper.getSysOperByOperNo(ShiroUserUtil.getUserName());
        String oldPass = ShiroUtil.createPassWord(oldPassword, oper.getSalt());
        if (!oldPass.equals(oper.getOperPwd())) {
            return CommonResult.strResult(0, "旧密码错误！");
        }
        String salt = ShiroUtil.createSalt();
        String passWord = ShiroUtil.createPassWord(newPassword, salt);
        oper.setOperPwd(passWord);
        oper.setSalt(salt);
        int num = sysOperatorMapper.update(oper);
        return CommonResult.ResponseResult(num);
    }

    @Override
    public Map<String, String> getOperAndRole() {
        Map<String, String> map = new HashMap<>();
        //赋初始值防止无数据导致前端解析错误
        map.put("operNo", "");
        map.put("operName", "");
        map.put("roleName", "");
        return sysOperatorMapper.getOperAndRoleByOperNo(ShiroUserUtil.getUserName());
    }

    @Override
    public PageInfo<SysOperator> fuzzySearch(Page page, String fuzzy) {
        String login = ShiroUserUtil.getUserName();
        //登录人地区
        String code = operUtil.getZoneCode();
        //只有紧跟在PageHelper.startPage方法后的第一个Mybatis的查询（Select）方法会被分页。
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<SysOperator> list = sysOperatorMapper.fuzzySearch(fuzzy, code);
        PageInfo<SysOperator> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public String selectOperNoByCompanyId(String opeNo) {
        BaseOrganization org = baseOrganizationService.getOrg(opeNo);
        return org.getId();
    }

    /**
     * 根据企业id查询外网用户列表
     *
     * @param page
     * @param sysOperator
     * @return
     */
    @Override
    public PageInfo<SysOperator> getOutUserListByCompanyId(Page page, SysOperator sysOperator) {
        List<SysOperator> list = new ArrayList<>();
        if (StringUtils.isBlank(sysOperator.getId())) {
            SysOperator operator = sysOperatorMapper.getOperInfoByOperNo(sysOperator.getOperNum());
            sysOperator.setGrade(operator.getGrade());
            PageHelper.startPage(page.getPageNum(), page.getPageSize());
            list = sysOperatorMapper.getOperNoListByCompanyId(sysOperator);
        } else {
            PageHelper.startPage(page.getPageNum(), page.getPageSize());
            list = sysOperatorMapper.getOutUserListByCompanyId(sysOperator);
        }
        PageInfo<SysOperator> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 根据企业类型查询角色List，用于新增外网用户时角色下拉框
     *
     * @return
     */
    @Override
    public List<SysRole> getRoleListByCompanyType(String operNo) {
        SysOperator operator = sysOperatorMapper.getOperInfoByOperNo(operNo);
        List<SysRole> sysRoleList = roleMapper.getRoleListByCompanyType(operator.getCompanyNo());
        return sysRoleList;

    }

    /**
     * 新增外网用户
     *
     * @param sysOperator
     * @return
     */
    @Override
    public CommonResult insertOutUser(SysOperator sysOperator) {
        sysOperator.setId(UUIDUtil.getUUID());
        sysOperator.setSalt(ShiroUtil.createSalt());
        if (StringUtils.isNotBlank(sysOperator.getOperPwd())) {
            sysOperator.setOperPwd(ShiroUtil.createPassWord(sysOperator.getOperPwd(), sysOperator.getSalt()));
        } else {
            sysOperator.setOperPwd(ShiroUtil.createPassWord(pwd, sysOperator.getSalt()));
        }
        //不确定启用人和启用时间在修改时是否需要填充数据，暂时未填入
        //sysOperator.setOpenOperName(ShiroUserUtil.getUserName());
        //sysOperator.setOperDate(DateUtils.getNow());
        sysOperator.setAddType("0");
        sysOperator.setGrade("2");
        SysOperator mainOper = getOperInfoByOperNo(sysOperator.getOperNo());
        sysOperator.setCompanyId(mainOper.getCompanyId());
        sysOperator.setCreater(mainOper.getOperNo());
        sysOperator.setCompanyNo(mainOper.getCompanyNo());
        sysOperator.setOperNo(generateAccount.generateAccount(mainOper.getCompanyNo()));
        sysOperator.setCreateTime(DateUtils.getNow());
        if (StringUtils.isBlank(sysOperator.getState())) {
            sysOperator.setState("1");
        }
        int num = sysOperatorMapper.insert(sysOperator);
        addRegionNo(sysOperator, mainOper.getOperNo());
        return CommonResult.ResponseResult(num, sysOperator.getOperNo());
    }

    /**
     * 修改外网用户
     *
     * @param sysOperator
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult updateOutOper(SysOperator sysOperator) {
        if (StringUtils.isNotBlank(sysOperator.getOperPwd())) {
            sysOperator.setSalt(ShiroUtil.createSalt());
            sysOperator.setOperPwd(ShiroUtil.createPassWord(sysOperator.getOperPwd(), sysOperator.getSalt()));
        }
        int num = sysOperatorMapper.updateOutOper(sysOperator);
        //todo
        SysOperator mainOper = getOperInfoByOperNo(sysOperator.getOperNo());
        if (mainOper != null) {
            //查询修改的账号的创建账号是否拥有小区权限
            List<BaseRegionInfo> allRegion = orgRegionService.getAllRegion(mainOper.getCreater());
            if (allRegion != null && !allRegion.isEmpty()) {
                List<String> collect = allRegion.stream().map(p -> p.getId()).collect(Collectors.toList());
                String regionIds = sysOperator.getRegionIds();
                if (StringUtils.isNotBlank(regionIds)) {
                    List<String> list = Arrays.asList(regionIds.split(","));
                    if (!collect.containsAll(list)) {
                        throw new CourseException(ShiroResultEnum.FAIL.getCode(), "该账号的主管账号[" + mainOper.getCreater() + "]没有小区的管辖权限，请先给主管账号添加");
                    }
                }
            }
        }
        //删除之前的数据
        orgRegionMapper.deleteOrgRegionByOperNo(sysOperator.getOperNo());
        orgBuildAuditMapper.deleteOrgBuildByOperNo(sysOperator.getOperNo());
        addRegionNo(sysOperator, sysOperator.getCreater());
        return CommonResult.ResponseResult(num);
    }

    /**
     * 添加绑定小区
     */
    private void addRegionNo(SysOperator sysOperator, String operNo) {
        if (StringUtils.isNotBlank(sysOperator.getRegionIds())) {
            for (String RegionId : sysOperator.getRegionIds().split(",")) {
                OrgRegion orgRegion = new OrgRegion();
                orgRegion.setId(UUIDUtil.getUUID());
                orgRegion.setRegionId(RegionId);
                orgRegion.setOperNo(sysOperator.getOperNo());
                orgRegion.setCreater(operNo);
                orgRegion.setCreateTime(DateUtils.getNow());
                orgRegionMapper.addOrgRegion(orgRegion);
                String mainOper = sysOperatorMapper.getMainOperatorByChildOper(sysOperator.getOperNo());
                //查询主账号管理的当前小区的自然幢
                List<OrgBuildAudit> list = orgBuildAuditMapper.getListByOperNoAndRegionId(RegionId, mainOper);
                for (OrgBuildAudit orgBuildAudit : list) {
                    orgBuildAudit.setOrgRegionAuditId(UUIDUtil.getUUID());
                    orgBuildAudit.setOperNo(sysOperator.getOperNo());
                    orgBuildAuditMapper.add(orgBuildAudit);
                }
            }
        }
    }

    /**
     * 绑定/换绑加密狗
     *
     * @param sysOperator
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public CommonResult bindUsbKey(SysOperator sysOperator, String type) {
        if (type == "1") {
            if (StringUtils.isBlank(sysOperator.getUsbKey())) {
                return CommonResult.ResponseResult(0, "未找到加密狗密钥");
            }
            //将其他绑定该加密狗的用户清空加密狗数据，确保加密狗只能被一个用户绑定
            sysOperatorMapper.setUsbKeyIsEmpty(sysOperator.getUsbKey());
        }
        int num = sysOperatorMapper.bindUsbKey(sysOperator);
        return CommonResult.ResponseResult(num);
    }

    /**
     * 根据登陆账号获取用户信息
     *
     * @param operNo
     * @return
     */
    @Override
    public SysOperator getOperInfoByOperNo(String operNo) {
        SysOperator operator = sysOperatorMapper.getOperInfoByOperNo(operNo);
        String companyNo = operator.getCompanyNo();
        String zoneCode;
        String corpName;
        if (FIVE.equals(companyNo) || SIX.equals(companyNo)) {
            //业委会或者居委会
            BaseOwnerCommittee info = baseOwnerCommitteeMapper.getInfo(operator.getCompanyId());
            zoneCode = info.getRegionCode();
            corpName = info.getOwnerCommitteeName();
        } else {
            //其他企业
            BaseOrganization info = baseOrganizationMapper.getInfo(operator.getCompanyId());
            zoneCode = info.getRegionCode();
            corpName = info.getOrgName();
        }
        String allZoneName = zoneCodeMapper.getAllZoneName(zoneCode);
        operator.setZoneCode(allZoneName);
        operator.setCorpName(corpName);
        return operator;
    }

    @Override
    public CommonResult getUsbKeyIsBind(String usbKey) {
        List<SysOperator> operList = sysOperatorMapper.getUsbKeyIsBind(usbKey);
        if (operList.size() > 0) {
            StringBuffer stringBuffer = new StringBuffer();
            return CommonResult.strResult(stringBuffer.append("该加密狗已被账号：").append(operList.get(0).getOperNo()).append("绑定，继续操作将该加密狗绑定到您的账号下.").toString());
        } else {
            return CommonResult.strResult("200");
        }
    }

    /**
     * 内网查询管辖区域内机构主账号列表
     *
     * @return
     */
    @Override
    public PageInfo<SysOperator> getOrgMainAccount(Page page, SysOperator sysOperator) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<SysOperator> list = sysOperatorMapper.getOrgMainAccount(sysOperator);
        PageInfo<SysOperator> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 账号启用停用
     *
     * @param operNo 账号
     * @param state  状态
     * @return
     */
    @Override
    public CommonResult openOrCloseAccount(String operNo, String state) {
        SysOperator sysOperator = new SysOperator();
        sysOperator.setOperNo(operNo);
        sysOperator.setState(state);
        int result = sysOperatorMapper.openOrCloseAccount(sysOperator);
        return CommonResult.ResponseResult(result);
    }

    @Override
    public List<BaseRegionInfo> selectOperNoByRegion(String type, String operNo) {
        List<BaseRegionInfo> baseRegionInfos = new ArrayList<>();
        switch (type) {
            case "05":
                baseRegionInfos = baseOwnerCommitteeMapper.selectRegionNoByOperNo(operNo);
                break;
            case "06":
                baseRegionInfos = baseOwnerCommitteeMapper.selectRegionNoByOperNo(operNo);
                break;
            default:
                baseRegionInfos = orgRegionMapper.selectRegionNoByOperNo(operNo);
                break;
        }
        return baseRegionInfos;
    }
}
